package com.dk.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.dk.pojo.TRole;
import com.dk.service.rolerservice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
@Controller
@RequestMapping("role")
public class rolecontroller {
    @Reference
    private rolerservice rolerservice;


    @RequestMapping("toshow")
    public String toshow(){

        return "role/show";
    }
    @RequestMapping("getinfo")
    @ResponseBody
    public List<TRole> getinfo(){
        List<TRole> list = rolerservice.selecteGetInfo();
        return list;
    }

    //zj
    @RequestMapping("toAdd")
    public String toAdd(){
        return "role/add";
    }
    @RequestMapping("insertActor")
    @ResponseBody
    public boolean insertActor(TRole role, @RequestParam("id")Integer[] id){
        return rolerservice.insertActor(role,id);
    }

    //xg
    @RequestMapping("toupdate/{roleId}")
    public String toupdate(@PathVariable("roleId")Integer roleId, Model model){
        TRole tRole = rolerservice.selectbyaid(roleId);
        model.addAttribute("a",tRole);
        return "role/update";
    }
    @RequestMapping("updateRole")
    @ResponseBody
    public boolean updateRole(@RequestParam("hid")Integer[] id,TRole tRole){
        boolean i = rolerservice.updategetinfo(id,tRole);
        return i;
    }

    @RequestMapping("deleteRole/{roleId}")
    @ResponseBody
    public boolean deleteRole(@PathVariable("roleId") Integer roleId){
        return rolerservice.deleteinfo(roleId);

    }

}
